// packageA/pages/detailArt/detailArt.js
import Share from "../../../lib/js/share.js";
import { writePhotosAlbum } from "../../../lib/js/util.js";
const font = require('../../../lib/js/font.js')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    height: app.globalData.height,
    titleBarHeight: app.globalData.titleBarHeight,
    windowHeight: app.globalData.windowHeight,
    navHeight: app.globalData.navHeight - 2,
    // 组件所需的参数
    nvabarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '', //导航栏 中间的标题
      color:'#2242A8'
    },
    contrastId: "",
    id: "",
    info:{},
    contrastInfo: {},
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.hideShareMenu(); //隐藏转发按钮
    font.loadFont(); //下载字体
    let that = this
    that.setData({
      contrastId: options.contrastId,
      id: options.id
    })
    that.getInfo()
    that.getContrastInfo()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  
  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  //   let that = this;
  //   return {
  //     title: that.data.info.name,
  //     path: '/packageA/pages/detailArt/detailArt?id=' + that.data.id + '&share=true&spread_code=' + that.data.spread_code + '&activity_type=' + that.data.activity_type + '&store_id=' + that.data.store_id,
  //     imageUrl: that.data.info.ui_img,
  //     success: function (res) {
  //       wx.showToast({
  //         title: "已转发",
  //         icon: 'none',
  //         duration: 2000
  //       })
  //     }
  //   }
  // },
  getInfo() {
    let that = this;
    app.fly.get('/ma/box/detail/' + that.data.id
    )
      .then(function (res) {

        if (res.code === 0) {
           that.setData({
              info: res.data
           })
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 2000
          });
        }
      })
  },
  getContrastInfo() {
    let that = this;
    app.fly.get('/ma/box/detail/' + that.data.contrastId
    )
      .then(function (res) {

        if (res.code === 0) {
          
           that.setData({
            contrastInfo: res.data
           })
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 2000
          });
        }
      })
  },
})